/*************************************************
 * Arrow.java                                    *
 * Generates and arrow at the specified x,y      *
 * coordinate of a graphics component            *
 *************************************************/
package graphics;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;

/**
 * Draws an arrow on the specified Graphics component
 *
 * @author      Gabriel Loewen
 */
public class Arrow {

    /**
     * Default constructor
     */
    public Arrow() {
    }

    /**
     * Draws a directed arrow on the specified Graphics component in the specified
     * location.
     *
     * @param g         The graphics component that needs to be drawn to
     * @param x         The x position of the arrow
     * @param y         The y position of the arrow
     * @param size      The size in pixels of the square
     * @param robotID   The name of the robot (depicted by the arrow)
     * @param heading   The direction that the arrow is pointed
     */
    public static void draw(Graphics2D g, int x, int y, int size, char heading, String robotID) {
        int unit = size / 5;

        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.95f));

        //Create a points for a polygon (arrow)
        Point p1 = new Point(x, y + size / 2);
        Point p2 = new Point(x + size / 2, y);
        Point p3 = new Point(x + size, y + size / 2);
        Point p4 = new Point(x + size / 2, y + size);

        //Set the color to yellow and paint the polygon dependant on the
        //directional heading
        g.setColor(Color.YELLOW);
        switch (heading) {
            case 'N':
                g.fillPolygon(new int[]{p4.x - unit / 2, p4.x - unit / 2, p4.x - size / 2, p2.x, p4.x + size / 2, p4.x + unit / 2, p4.x + unit / 2},
                        new int[]{p4.y, p1.y, p1.y, p2.y, p3.y, p3.y, p4.y}, 7);
                break;
            case 'S':
                g.fillPolygon(new int[]{p2.x + unit / 2, p2.x + unit / 2, p2.x + size / 2, p4.x, p2.x - size / 2, p2.x - unit / 2, p2.x - unit / 2},
                        new int[]{p2.y, p3.y, p3.y, p4.y, p1.y, p1.y, p2.y}, 7);
                break;
            case 'E':
                g.fillPolygon(new int[]{p1.x, p2.x, p2.x, p3.x, p2.x, p2.x, p1.x},
                        new int[]{p1.y - unit / 2, p1.y - unit / 2, p1.y - size / 2, p3.y, p1.y + size / 2, p1.y + unit / 2, p1.y + unit / 2}, 7);
                break;
            case 'W':
                g.fillPolygon(new int[]{p3.x, p4.x, p4.x, p1.x, p2.x, p2.x, p3.x},
                        new int[]{p3.y + unit / 2, p3.y + unit / 2, p3.y + size / 2, p1.y, p3.y - size / 2, p3.y - unit / 2, p3.y - unit / 2}, 7);
        }
    }
}
